// pages/netCase/registerCase/registerCase.js

import ecfsConfig from '../../../config/ecfs.config.js'
import locale from '../../../config/locale/zh-CN/netCase/caseList.js'
import { merge } from '../../../utils/util.js'
import * as registerCaseBusiness from '../../../js/netCase/registerCase/registerCaseBusiness.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    locale,
    caseInfo: {},
    operateCaseStateList: {},
    templateIsHidden: true, //诉讼请求与事实理由范文是否隐藏
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const operateCaseStateList = wx.getStorageSync('operateCaseStateList')
    let caseInfo = {
      requestFact: {
        request: '',
        fact: '',
      }
    }
    if (!operateCaseStateList.isAdd) {
      caseInfo = wx.getStorageSync('caseInfo')
    } else {
      wx.setStorage({
        key: 'caseInfo',
        data: {},
      })
    }
    this.setData({
      operateCaseStateList,
      caseInfo,
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  cancel(e) {
    if (this.data.operateCaseStateList.isAdd) {
      wx.navigateTo({
        url: '/pages/netCase/caseList/caseList',
      })
    } else {
      wx.navigateTo({
        url: '/pages/netCase/caseInfo/caseInfo',
      })
    }
  },
  next(e) {
    registerCaseBusiness.judgeIsCanSkipToEvidence(this)
  },
  bindRequestBlur(e) {
    let that = this
    let request = e.detail.value
    let isHasRequestVar = 'operateCaseStateList.isHasRequest'
    this.setData({
      [isHasRequestVar]: !!request
    }, () => {
      wx.setStorage({
        key: 'operateCaseStateList',
        data: that.data.operateCaseStateList,
      })

    })
    let requestVariable = 'caseInfo.requestFact.request'
    this.setData({
      [requestVariable]: request
    }, () => {
      wx.setStorage({
        key: 'caseInfo',
        data: that.data.caseInfo,
      })
    })

  },
  bindFactBlur(e) {
    let that = this
    let fact = e.detail.value
    let isHasFactVar = 'operateCaseStateList.isHasFact'
    this.setData({
      [isHasFactVar]: !!fact
    }, () => {
      wx.setStorage({
        key: 'operateCaseStateList',
        data: that.data.operateCaseStateList,
      })

    })
    let factVariable = 'caseInfo.requestFact.fact'
    this.setData({
      [factVariable]: fact
    }, () => {
      wx.setStorage({
        key: 'caseInfo',
        data: that.data.caseInfo,
      })
    })
  },
  addPerson(e) {
    console.log(e)
    const formIsFrom = e.target.dataset.type
    if (formIsFrom !== '4') {
      wx.navigateTo({
        url: '/pages/netCase/party/party?formIsFrom=' + formIsFrom,
      })
    } else {
      wx.navigateTo({
        url: '/pages/netCase/agent/agent?formIsFrom=' + formIsFrom,
      })
    }
  },
  skipToPersonEdit(e) {
    console.log(e)
    const partyId = e.target.dataset.partyid
    wx.navigateTo({
      url: '/pages/netCase/party/party?formIsFrom=0&partyId=' + partyId,
    })
  },
  skipToAgentEdit(e) {
    console.log(e)
    const agentId = e.target.dataset.agentid
    wx.navigateTo({
      url: '/pages/netCase/agent/agent?formIsFrom=5&agentId=' + agentId,
    })
  },
  showTemplate(e) {
    console.log('----------')
    // this.setData({
    //   templateIsHidden: false
    // })
    // wx.showModal({
    //   title: 'sdfdsfd',
    //   content: '请求法院判令被告李四偿还原告借款本金25万元，利息2655元;\t请求法院判令被告李四向原告张三支付从逾期日期起至实际清偿之日止的利息和罚息（暂从2015年4月20日起，以剩余本金150000元为基数，按年利率0.5%计算至2016年7月20日的金额为2000元);##请求法院判令若被告李四未能偿还上述债务，则以被告所有的大众汽车变卖的价款优先受偿;##请求法院判令被告支付律师费3000元;请求法院判令被告承担本案的全部诉讼费用。',
    // })
    //this.data.templateIsHidden = true
  },
  hideDialog(e) {
    // this.setData({
    //   templateIsHidden: true
    // })
  },
  showDialog(e) {
    // this.setData({
    //   templateIsHidden: false
    // })
  }
})